package org.example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.common.JsonResult;
import org.example.entity.BankCardIntroduceEntity;
import org.example.enums.BankCardTypeEnums;
import org.example.service.BankCardIntroduceService;
import org.example.service.TbBankInfoService;
import org.example.service.utils.IConst;
import org.example.vo.TbBankInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/userinfo")
@Api(tags = IConst.MODULE_OPEN_BLANK_CARD)
@Slf4j
public class TbBankInfoController {

    @Resource
    private TbBankInfoService tbBankInfoService;

    @Autowired
    private BankCardIntroduceService bankCardIntroduceService;
    @PostMapping("/saveBank")
    @ApiOperation(value = "用户开户申请", tags = IConst.MODULE_OPEN_BLANK_CARD)
    public JsonResult<Boolean> saveBank(@RequestBody TbBankInfoVo tbBankInfoVo){
        boolean flag =  tbBankInfoService.saveBank(tbBankInfoVo);
        return JsonResult.ok(flag);
    }

    @ApiOperation("获取环境")
    @PostMapping("/queryEnv")
    public JsonResult queryEnv(){
        log.info("获取环境");
        String result = bankCardIntroduceService.lambdaQuery()
                .eq(BankCardIntroduceEntity::getType, BankCardTypeEnums.APP_ENV)
                .list()
                .stream().findFirst()
                .map(BankCardIntroduceEntity::getInfoVal)
                // 生产环境
                .orElse("1");
        return JsonResult.ok(result);
    }
}
